package com.glxy;

import com.glxy.dao.impl.AddressDaoImpl;
import com.glxy.dao.impl.ProviderDaoImpl;
import com.glxy.dao.impl.UserDaoImpl;
import com.glxy.pojo.Address;
import com.glxy.pojo.Provider;
import com.glxy.pojo.User;
import org.junit.Test;

import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.ArrayList;

public class TestSms {

    @Test
    public void Test() throws ClassNotFoundException, IllegalAccessException {

        Provider provider = new ProviderDaoImpl().findAll().get(0);
        System.out.println(provider.getCreationDate());
        System.out.println(provider.getCreationDate().getYear()+"-"+provider.getCreationDate().getMonthValue()+"-"+provider.getCreationDate().getDayOfMonth());

        UserDaoImpl userDao = new UserDaoImpl();
        ArrayList<User> list = userDao.findAll();

        System.out.println(LocalDateTime.now().getYear());
        System.out.println(list.get(0).getBirthday().toLocalDate().getYear());
        System.out.println(LocalDateTime.now().getYear() - list.get(0).getBirthday().toLocalDate().getYear());

//        User user = new User();
//
//        user.setId(99);
//        user.setUserCode("a01");
//        user.setUserCode("123");

//        userDao.delete(new Long(99));


//        AddressDaoImpl addressDao = new AddressDaoImpl();
//        ArrayList<Address> list = new ArrayList<>();
//        Field[] fields = Class.forName("com.glxy.pojo.Address").getDeclaredFields();
//
//        Address address = new Address();
//        address.setId(new Long(99));
//        address.setContact("wyf");
//        address.setPostCode("10086");
//
//        addressDao.insert(address);
//
//        list = addressDao.findAll();
//
//        for (Field field : fields) {
//            field.setAccessible(true);
//            System.out.print(field.getName()+"|");
//        }
//        System.out.println();
//        for (Address addr : list) {
//            for (Field field : fields) {
//                field.setAccessible(true);
//                if (field.get(addr) != null){
//                    System.out.print(field.get(addr) + "|");
//                }
//            }
//            System.out.println();
//        }
//
//        System.out.println();System.out.println();System.out.println();
//
//        address.setContact("xjn");
//        addressDao.update(address);
//
//
//        list = addressDao.findAll();
//        for (Field field : fields) {
//            field.setAccessible(true);
//            System.out.print(field.getName()+"|");
//        }
//        System.out.println();
//        for (Address addr : list) {
//            for (Field field : fields) {
//                field.setAccessible(true);
//                if (field.get(addr) != null){
//                    System.out.print(field.get(addr) + "|");
//                }
//            }
//            System.out.println();
//        }
//
//        System.out.println();System.out.println();System.out.println();
//
//
//
//        addressDao.delete(new Long(99));
//
//
//        list = addressDao.findAll();
//        for (Field field : fields) {
//            field.setAccessible(true);
//            System.out.print(field.getName()+"|");
//        }
//        System.out.println();
//        for (Address addr : list) {
//            for (Field field : fields) {
//                field.setAccessible(true);
//                if (field.get(addr) != null){
//                    System.out.print(field.get(addr) + "|");
//                }
//            }
//            System.out.println();
//        }


//        Address address = new Address();
//
//        address.setContact("test");
//
//        Field[] fields;
//
//        Class clazz = Class.forName("com.glxy.pojo.Address");
//
//        fields = clazz.getDeclaredFields();
//
//        Iterator<Field> it = Arrays.stream(fields).iterator();
//
//        while (it.hasNext()) {
//            Field field = it.next();
//            System.out.println(field.getName());
//            System.out.println(field.getType());
//            field.setAccessible(true);
//            if (field.get(address) != null) {
//                System.out.println(field.get(address));
//            }
//
//        }

    }
}
